package com.bike.bikeserver.controller.backend;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.BikeRequest;
import com.bike.bikeserver.service.IBikeRequestService;
import com.bike.bikeserver.service.impl.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.bike.bikeserver.constant.Constants.*;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/19 22:37
 */
@RestController
@RequestMapping("back/bikeRequest")
public class BackBikeRequestController
{
    @Autowired
    IBikeRequestService bikeRequestService;
    @Autowired
    SysRoleService sysRoleService;

    /**
     * 获取全部请求列表
     *
     * @return
     */
    @GetMapping("getBikeRequestList")
    public CommonResult getBikeRequestList()
    {
        return bikeRequestService.getBikeRequestList();
    }

    /**
     * 根据用户名[精确]获取请求列表
     *
     * @param requestApplier
     * @return
     */
    @OperationLog(value = "根据用户名精确获取请求列表:bike_request")
    @GetMapping("getBikeRequestByName")
    public CommonResult getBikeRequestByNameOfBack(@RequestParam("requestApplier") String requestApplier)
    {
        return bikeRequestService.getBikeRequestByNameOfBack(requestApplier);
    }

    /**
     * 修改请求的类型或区域名称
     *
     * @param bikeRequest
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id修改请求的类型或区域名称:bike_request")
    @PutMapping("editBikeRequestById")
    public CommonResult editBikeRequestById(@RequestBody BikeRequest bikeRequest)
    {
        return bikeRequestService.editBikeRequestById(bikeRequest);
    }

    /**
     * 删除某个请求
     *
     * @param bikeRequest
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id删除某个请求:bike_request")
    @DeleteMapping("deleteBikeRequestById")
    public CommonResult deleteBikeRequestById(@RequestBody BikeRequest bikeRequest)
    {
        return bikeRequestService.deleteBikeRequestById(bikeRequest);
    }

    /**
     * 将未处理的请求移交至调度表等待处理
     * @param bikeRequest
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog("将未处理的请求移交至调度表等待处理:bike_request")
    @PostMapping("applyRequestToDispatch")
    public CommonResult applyRequestToDispatch(@RequestBody BikeRequest bikeRequest)
    {
        return bikeRequestService.applyRequestToDispatch(bikeRequest);
    }

}